package com.ocom.webapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.request.payconfig.KitchenPrinter.*;
import com.ocom.common.request.web.GetPointMealSendReportsRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.vo.payconfig.kitchenprinter.PlanKitchenPrinterRequest;
import com.ocom.security.authentication.YoCiUser;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.CompanyClientService;
import com.ocom.webapi.feign.PayConfigClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
@Slf4j
public class KitchenPrinterController {

    @Autowired
    private PayConfigClientService payConfigClientService;
    @Autowired
    private CompanyClientService companyClientService;


    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterOnShow)
    public Result KitchenPrinterOnShow(@RequestBody KitchenPrinterOnShowRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Long comId = yoCiUser.getComId();
        request.setComId(comId);
        return payConfigClientService.kitchenPrtList(request);
    }

    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterAdd)
    public Result KitchenPrinterAdd(@RequestBody KitchenPrinterAddRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Long comId = yoCiUser.getComId();
        request.setComId(comId);
        return payConfigClientService.feieNewPtr(request);
    }

    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterModify)
    public Result KitchenPrinterModify(@RequestBody KitchenPrinterModifyRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Long comId = yoCiUser.getComId();
        request.setComId(comId);
        return payConfigClientService.feieUpdatePtr(request);
    }

    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterScheme)
    public Result KitchenPrinterScheme(@RequestBody KitchenPrinterSchemeRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Long comId = yoCiUser.getComId();
        request.setComId(comId);
        return payConfigClientService.setKitchenPrtScheme(request);
    }


    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterDelete)
    public Result KitchenPrinterDelete(@RequestBody KitchenPrinterDeleteRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Long comId = yoCiUser.getComId();
        request.setComId(comId);
        return payConfigClientService.feieRemovePtr(request);
    }

    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterCleanSqs)
    public Result KitchenPrinterCleanSqs(@RequestBody KitchenPrinterCleanSqsRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        Long comId = yoCiUser.getComId();
        request.setComId(comId);
        return payConfigClientService.feieCleanSqs(request);
    }

    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterFeiePrintMsg)
    public Result feiePrintMsg(@RequestBody JSONObject request) {
        return payConfigClientService.feiePrintMsg(request);
    }

    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterPlanKitchenPrinter)
    public Result planKitchenPrinter(@RequestBody PlanKitchenPrinterRequest request) {
        return payConfigClientService.planKitchenPrinter(request);
    }


    @PostMapping(WebApiServiceUrl.Url_KitchenPrinterUserPrint)
    public Result kitchenPrinterUserPrint(@RequestBody GetPointMealSendReportsRequest request) {
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setComId(yoCiUser.getComId());
        return payConfigClientService.kitchenPrtByComId(request);
    }
}
